package com.cskaoyan.market.util;

import com.cskaoyan.market.exception.ApiException;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Set;

/**
 * @author lixianbiao
 * @since 2024/06/29 09:22
 */
public class ValidUtil {
    public static <T> void valid(Validator validator, T target,Class<?>... var2){
        Set<ConstraintViolation<T>> validate = validator.validate(target,var2);
        if(!validate.isEmpty()){
            ConstraintViolation<T> next = validate.iterator().next();
            throw new ApiException(402,next.getMessage());
        }
    }
}